package torpedo_client;

import torpedo_client.playerthreads.Connection;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Popup extends JFrame {

    private JLabel help = new JLabel("Adja meg a szerver adatait!");
    private JLabel ipLab = new JLabel("Ip: ");
    private JLabel portLab = new JLabel("Port: ");
    private JButton ok = new JButton("Ok");
    private JButton cancel = new JButton("Mégse");
    private JTextField ip = new JTextField(16);
    private JTextField port = new JTextField(6);
    private JPanel textPanel = new JPanel();
    private JPanel buttonPanel = new JPanel();
    private JPanel helpPanel = new JPanel();

    public Popup() {

        setTitle("Új játék");
        setBounds(300, 100, 500, 150);
        setVisible(true);
        setResizable(false);
        setLayout(new BorderLayout());

        cancel.addActionListener(
                new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        setVisible(false);
                    }
                });
        ok.addActionListener(
                new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Connection con = new Connection(ip.getText(), Integer.parseInt(port.getText()));
                        con.start();
                    }
                });

        helpPanel.add(help);
        textPanel.add(ipLab);
        textPanel.add(ip);
        textPanel.add(portLab);
        textPanel.add(port);
        buttonPanel.add(ok);
        buttonPanel.add(cancel);

        add(helpPanel, "North");
        add(textPanel, "Center");
        add(buttonPanel, "South");

    }
}
